package what.basic.file;

import java.io.*;

public class fileread {
public static String filereadwithfileinputstream(String file){
	String fs="";
	FileInputStream filein=null;
	if(file!=null){
		try{
			filein=new FileInputStream(file);
		}
		catch(FileNotFoundException fe){
			//lbl.setText("File not found");
			fe.printStackTrace();
			return "";
		}
		int readbyte;
		try{
			while((readbyte=filein.read())!=-1){
		fs=fs + String.valueOf((char)readbyte);
			}
		}
		catch(IOException ioe){
	//		lbl.setText("read file error");
		}
		finally{
			try{
				if(filein!=null){
					filein.close();
				}
			}
			catch(IOException ioe2){}
		}
	}
	return fs;	
}
public static String filereadwithbufferedreader(String file){
	String fs="";
	if (file!=null){
		try{
			File f=new File(file);
			FileInputStream fr=new FileInputStream(f);
			BufferedReader br=new BufferedReader(new InputStreamReader(fr,"UTF-8"));
			String str;
			while ((str=br.readLine())!=null){
				fs=fs +'\r'+'\n'+ str;
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
	return fs;
}
	public static void main(String[] args) {
		String xx=filereadwithbufferedreader("e:\\4.txt");
		System.out.println(xx);
	}
}
